//Before authenticating requests,
// the strategy (or strategies) used by an application must be configured.
const passport = require('passport');
const LocalStrategy = require('passport-local').Strategy;
const User = require('mongoose').model('User');

module.exports = function () {
    passport.use(new LocalStrategy((username, password, done)=>{
        User.findOne({username:username}, (err, user)=>{
            if(err) {return done(err);}
            if(!user) {return done(null, false);}
            if(!user.verifyPassword(password)) {return done(null, false);}
            return done(null, user);
        });
    }));
};